<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page  import="java.sql.*"%>
<%@page import="com.jdbc.tool.DBLianjie"%>
<%@page import="com.book.Dao.SelectAllBook"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<% 
String fenlei=null;
if(request.getParameter("bookid")!=null){
	fenlei = new String(request.getParameter("bookid").getBytes("iso8859-1"),"utf-8"); 
}
System.out.print(fenlei);

int pageNum = 1;//当前是第几页。
String spageNum = request.getParameter("pageNum");
//一般第一次刷新都没带pageNum来，所以是空，判断是空，就选择默认的pageNum.
if (spageNum != null) {
	pageNum = Integer.parseInt(spageNum);
}

int pageCount = 3;//共有多少页。
int pageSize = 4;//每一页的大小。
int rowCount = 1;//共有多少行数据

Connection conn=null;
Statement stm=null;
ResultSet rs=null;
conn=DBLianjie.getconn();
try {
	stm=conn.createStatement();
	//查询rowcount。
	rs = stm.executeQuery("select count(*) from book where FENLEIID="+fenlei+"");
	rs.next();
	rowCount = rs.getInt(1);
	//得到pagecount
	pageCount = rowCount % pageSize == 0 ? rowCount / pageSize
			: rowCount / pageSize + 1;
	rs = stm
	.executeQuery("select * from (select t.*,rownum rn from(select * from book where FENLEIID="+fenlei+" order by bookid) t "
			+ "where rownum<="
			+ pageSize
			* pageNum
			+ ")where rn>=" + (pageSize * (pageNum - 1) + 1));
} catch (SQLException e) {
	e.printStackTrace();
}
    session.setAttribute("pageNum",pageNum);
    session.setAttribute("pageCount",pageCount);
    session.setAttribute("fenlei",fenlei);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>图书列表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" type="text/css" href="<c:url value='../bookcss/list.css'/>">
	<link rel="stylesheet" type="text/css" href="<c:url value='../qiantai/pager/pager.css'/>" />
  </head>
  
  <body>
<div style="width:100%;height:100%; overflow-y:scroll; border:1px solid;">
<% while(rs.next()){
	String booktime="";
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	if (rs.getString("booktime") != null){
		booktime = sdf.format(new Date(rs.getDate("booktime").getTime()));	
	}

%>    
<ul>
  <li>
  <div class="inner">
    <a class="pic" href="<c:url value='Goudesc.jsp'/>?bookname=<%=rs.getString("BOOKNAME")%>
    &bookimg=<%=rs.getString("bookimg")%>&bookid=<%=rs.getString("BOOKID")%>&bookprice=<%=rs.getString("PRICE")%>
    &zuozhe=<%=rs.getString("ZUOZHE")%>&chubanshe=<%=rs.getString("CHUBANSHE")%>&time=<%=booktime%>
    &feileiid=<%=rs.getString("FENLEIID")%>
    ">
    <img src="<%=rs.getString("bookimg")%>" border="0"/>
    </a>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p class="price">
		<span class="price_n">&yen;<%=rs.getFloat("PRICE")%></span>
		
	</p>
	<p><a id="bookname" title="<%=rs.getString("BOOKNAME")%>" href="Goudesc.jsp?bookname=<%=rs.getString("BOOKNAME")%>
    &bookimg=<%=rs.getString("bookimg")%>&bookid=<%=rs.getString("BOOKID")%>&bookprice=<%=rs.getString("PRICE")%>
    &zuozhe=<%=rs.getString("ZUOZHE")%>&chubanshe=<%=rs.getString("CHUBANSHE")%>&time=<%=booktime%>
    &feileiid=<%=rs.getString("FENLEIID")%>">
	<%=rs.getString("BOOKNAME")%>&nbsp;&nbsp;&nbsp;&nbsp;
	作者：<%=rs.getString("ZUOZHE")%></a>
	</p>
	<p class="publishing">
		<span>出 版 社：</span><%=rs.getString("CHUBANSHE")%>
	</p>
	<p class="publishing_time"><span>出版时间：</span><%=rs.getDate("BOOKTIME")%></p>
  </div>
  </li>
</ul>
<% }%>
					<div style="float:left; width: 100%; text-align: center;">
						<hr/>
						<br/>
						<%@include file="../qiantai/pager/pager.jsp" %>
					</div>
</div>
  </body>
 
</html>
